package com.yuba.front.controller.fishSite;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.yuba.common.idempotent.annotation.RepeatSubmit;
import com.yuba.common.log.annotation.Log;
import com.yuba.common.web.core.BaseController;
import com.yuba.common.mybatis.core.page.PageQuery;
import com.yuba.common.core.domain.R;
import com.yuba.common.core.validate.AddGroup;
import com.yuba.common.core.validate.EditGroup;
import com.yuba.common.log.enums.BusinessType;
import com.yuba.common.excel.utils.ExcelUtil;
import com.yuba.front.domain.vo.FishSiteVo;
import com.yuba.front.domain.bo.FishSiteBo;
import com.yuba.front.service.IFishSiteService;
import com.yuba.common.mybatis.core.page.TableDataInfo;

/**
 * 钓场
 *
 * @author modakai
 * @date 2024-12-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fishSite/fishSite")
public class FishSiteController extends BaseController {

    private final IFishSiteService fishSiteService;

    /**
     * 查询钓场列表
     */
    @SaCheckPermission("fishSite:fishSite:list")
    @GetMapping("/list")
    public TableDataInfo<FishSiteVo> list(FishSiteBo bo, PageQuery pageQuery) {
        return fishSiteService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出钓场列表
     */
    @SaCheckPermission("fishSite:fishSite:export")
    @Log(title = "钓场", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FishSiteBo bo, HttpServletResponse response) {
        List<FishSiteVo> list = fishSiteService.queryList(bo);
        ExcelUtil.exportExcel(list, "钓场", FishSiteVo.class, response);
    }

    /**
     * 获取钓场详细信息
     *
     * @param fishSiteId 主键
     */
    @SaCheckPermission("fishSite:fishSite:query")
    @GetMapping("/{fishSiteId}")
    public R<FishSiteVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long fishSiteId) {
        return R.ok(fishSiteService.queryById(fishSiteId));
    }

    /**
     * 新增钓场
     */
    @SaCheckPermission("fishSite:fishSite:add")
    @Log(title = "钓场", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FishSiteBo bo) {
        return toAjax(fishSiteService.insertByBo(bo));
    }

    /**
     * 修改钓场
     */
    @SaCheckPermission("fishSite:fishSite:edit")
    @Log(title = "钓场", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FishSiteBo bo) {
        return toAjax(fishSiteService.updateByBo(bo));
    }

    /**
     * 删除钓场
     *
     * @param fishSiteIds 主键串
     */
    @SaCheckPermission("fishSite:fishSite:remove")
    @Log(title = "钓场", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fishSiteIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] fishSiteIds) {
        return toAjax(fishSiteService.deleteWithValidByIds(List.of(fishSiteIds), true));
    }
}
